package com.chenchao.javafile;

import java.io.*;

/**
 * @encoding : UTF-8
 * @Time : 2020/11/15 17:02
 * @Author : Chen Chao
 * @File : javaSE.com.chenchao.javaFile.Test8.java
 * @Software : IntelliJ IDEA
 * @since : 1.8
 * 字符缓冲流
 */
public class Test8 {
    public static void main(String[] args) {
        //test1();
        tset2();

    }

    /**
     * 字符输出缓冲流
     */
    public static void test1(){
        File file = new File("myjava01/src/fo/aa.txt");
        //构造方法
        try (BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(file));)
        {
            bufferedWriter.newLine();
            //特有换行方法，比\r\n兼容性更好
            bufferedWriter.write("adfvdfadv");
            bufferedWriter.newLine();
            bufferedWriter.newLine();
            bufferedWriter.write("adfvdfadv");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 字符输入缓冲流
     */
    public static void tset2(){
        File file = new File("myjava01/src/fo/aa.txt");
        //构造方法
        try (BufferedReader bufferedReader = new BufferedReader(new FileReader(file));)
        {
            String str="";
            //特有方法读下一行
            while ((str=bufferedReader.readLine())!=null){
                System.out.println(str);
            }

        } catch (IOException e) {

            e.printStackTrace();
        }
        System.out.println();
    }
}
